#include <stdio.h>
#include <stdlib.h>

#include "sqlite3.h"

#define INSERT "insert into studen values(NULL, '%s','%s');"
#define DBNAME "/tmp/mysql.db"

int main(void)
{
	printf("Content-Type:text/html\n\n");
	sqlite3 *ppdb;
	int ret = sqlite3_open(DBNAME, &ppdb);  //打开数据库
	if(ret != SQLITE_OK)
	{
		printf("open db error\n\n");
		return -1;
	}
	
	char insert[128]={0};
	char name[32] = {0};
	char ip[32] = {0};

	char *data = getenv("QUERY_STRING");
	if(data == NULL)
		printf("<p>error no input </p>\n\n");
	else
		sscanf(data,"name=%[^&]&ip=%s",name,ip);
	printf("%s %s\n\n",name,ip);
		
	
	

	sprintf(insert,INSERT,name,ip);

	char *err = NULL;
	ret = sqlite3_exec(ppdb, insert, NULL, NULL, &err); //err 数据库错误输出
	if(ret != SQLITE_OK)
	{
		printf("%s\n\n",err);
		return -1;
	}	
	printf("install suc");
	sqlite3_close(ppdb);
	
	return 0;	
}
